//
//  PartsItemV.m
//  ProjectforHDX
//
//  Created by HDX on 16/8/8.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "PartsItemV.h"
@interface PartsItemV()



@property(nonatomic,copy) PartsItemVBlock clickBlock;
@property(nonatomic,strong) NSMutableArray *data;
@end

@implementation PartsItemV
/**
 *  创建包裹图层
 *
 *  @param frame
 *  @param logis 物流信息
 *
 *  @return
 */
-(id)initDHVWithFram:(CGRect)frame ordinal:(int )i Data:(NSArray*)data  onClick:(PartsItemVBlock)success;{
    self=[super initWithFrame:frame];
    if(self){
        self.clickBlock=success;
        self.data=[data mutableCopy];
        RZCustomButtom *btnParts=[[RZCustomButtom alloc] init];
        UIImage *icon=BDFILEIMAGENAEM(@"wareHouseDeliver/deliverPacking");
        [btnParts setImage:icon forState:UIControlStateNormal];
        [btnParts setFrame:CGRectMake((self.width-icon.size.width)/2.f,5,icon.size.width,icon.size.height)];
        [self addSubview:btnParts];
        btnParts.tag=101;
        [btnParts addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        RZCustomButtom *deleteBtn=[[RZCustomButtom alloc] init];
        
        UIImage *delicon=BDFILEIMAGENAEM(@"wareHouseDeliver/deliverDelete");
        [deleteBtn setImage:delicon forState:UIControlStateNormal];
        
        [deleteBtn setFrame:CGRectMake(btnParts.right-20,5,20,20)];
        [self addSubview:deleteBtn];
        deleteBtn.tag=102;
        [deleteBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        CustomLabel *labUrgent=[[CustomLabel alloc] initWithFrame:CGRectMake(0,self.height-20, self.width, 20)];
        labUrgent.textAlignment=NSTextAlignmentCenter;
        [labUrgent setFont:CustomFont(13)];
 
        NSString *htmlString=[NSString stringWithFormat:@"<font color='blue'>%ld</font>/%ld",(long)i,(long)data.count];
 
        NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        
        labUrgent.attributedText=attrStr;
        labUrgent.numberOfLines=1;
        [self addSubview:labUrgent];
        
    }
    return self;
    
}

-(void)btnClick:(RZCustomButtom*)sender{
                if(self.clickBlock){
                
                    switch (sender.tag) {
                        case  101:
                        {
                            
                            self.clickBlock(YES);
                            
                        }
                            break;
                        case  102:
                        {
                            self.clickBlock(NO);
                        }
                            break;
                        default:
                            break;
                    }
                }
  
}
@end
